using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using DynamicChart.Annotation;

namespace DynamicChart.Util;

public class ClassLoader
{
    public static List<Type> LoadClass<T>(string folderPath) where T : Attribute
    {
        List<Type> types = LoadClass();
        List<Type> result = new List<Type>();

        foreach (Type type in types)
        {
            try
            { 
                if (type.GetCustomAttribute<T>() != null)
                {
                    result.Add(type);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"检查类型 {type.FullName} 时出错: {ex.Message}");
            }
        }

        return result;
    }
    
    public static List<Type> LoadClass()
    {
        var result = new List<Type>();

        Assembly assembly = Assembly.GetExecutingAssembly(); 

        foreach (var type in assembly.GetTypes())
        { 
            result.Add(type);
        }

        return result;
    }
}
